<?php
/**
 * Created by IntelliJ IDEA.
 * User: Rookiejin<mrjnamei@gmail.com>
 * Date: 2018/3/8
 * Time: 12:13
 */

namespace App\Winged\Patients\Controllers;


use App\Winged\Auth\Backend\Api\Api;
use App\Winged\Components\Content;
use Illuminate\Http\Request;

class SpaController extends BaseController
{

    public function index()
    {
        return $this->Content(function (Content $content) {
            $view  = view('winged.patients::spa.index');
            $content->body($view);
        });
    }

    public function updateForm(Request $request)
    {
        $path   = $request->input('path');
        $params = $request->input('params' , null);
        $method = strtoupper($request->input('method' , 'GET'));

        if(isset($params ['property']) && count($params['property']) == 0 ){
            $params ['property'] = new \stdClass();
        }
        try {
            list($status , $content) = Api::doTransfer($path ,$method , $params);
            return response()
                ->json(['status' => $status, 'content' => $content]);
        }
        catch (\Exception $e) {
            return response()->json(['msg' => $e->getMessage() , 'status' => 500]);
        }
    }
}